<?php
declare (strict_types = 1);

namespace app\frontend\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Article extends Model
{
    // 模型关联，关联article_content表
    public function articleContent()
    {
        return $this->hasOne(ArticleContent::class);
    }

    // 模型关联，关联article_category表
    public function articleCategory()
    {
        return $this->belongsTo(ArticleCategory::class)
            ->bind(['category' => 'title']);
    }

    // 模型关联，关联user表
    public function user()
    {
        return $this->belongsTo(User::class)
            ->bind(['author' => 'nickname']);
    }

    // 获取器
    public function getStatusAttr($value)
    {
        $status = [
            1 => '草稿',
            2 => '发布'
        ];
        return $status[$value];
    }
}
